<template>
  <div class="app-container">
    <el-card>
      <el-form
        :model="queryParams"
        ref="queryRef"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="客户姓名">
          <el-input
            v-model="queryParams.applyName"
            placeholder="请输入客户姓名"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>

        <el-form-item label="服务开始时间" style="font-weight: 700">
          <el-date-picker
            v-model="queryParams.planBeginTime"
            type="datetime"
            placeholder="选择服务开始时间"
            value-format="YYYY-MM-DD hh:mm:ss"
          />
          ~
          <el-date-picker
            v-model="queryParams.planEndTime"
            type="datetime"
            placeholder="选择服务结束时间"
            value-format="YYYY-MM-DD hh:mm:ss"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search"
@click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="warning" plain icon="Download" @click="handleExport"
            >导出</el-button
          >
        </el-col>
        <right-toolbar
          v-model:showSearch="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table
        v-loading="loading"
        :data="postList"
        stripe
        border
        max-height="500"
      >
        <el-table-column label="工单编号" align="center" prop="workOrderCode" />
        <el-table-column label="客户姓名" align="center" prop="applyName" />
        <el-table-column label="身份证号" align="center" prop="idCard" />
        <el-table-column label="服务项目" align="center" prop="serviceItemName">
        </el-table-column>
        <el-table-column label="合计金额" align="center" prop="totalPrice" />
        <el-table-column
          label="社区站点"
          align="center"
          prop="communitySiteName"
        />

        <el-table-column label="服务人员" align="center" prop="communitySitePersonnelName" />
        <el-table-column
          label="服务开始时间"
          align="center"
          prop="planBeginTime"
        />
        <el-table-column
          label="服务结束时间"
          align="center"
          prop="planEndTime"
        />

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="220"
        >
          <template #default="scope">
            <el-button link
type="primary" @click="handinfo(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.limit"
        @pagination="getList"
      />
    </el-card>

    <!-- 添加或修改岗位对话框 -->
  </div>
</template>

<script setup name="elderlyReformExpense">
const { proxy } = getCurrentInstance();
const { sys_normal_disable, sys_user_sex } = proxy.useDict(
  'sys_normal_disable',
  'sys_user_sex',
)
const router = useRouter();

import { workOrderFee } from '@/api/Expense/index';

const showSearch = ref(true);
const loading = ref(true);
const postList = ref([]);

const total = ref(0);

const data = reactive({
  form: {},
  queryParams: {
    page: 1,
    limit: 10,
    applyName: undefined,
    planBeginTime: undefined,
    planEndTime: undefined,
  },
  rules: {},
});

const { queryParams, form, rules } = toRefs(data);

/** 查询岗位列表 */
function getList() {
  if (queryParams.value.planBeginTime > queryParams.value.planEndTime) {
    proxy.$modal.msgError("开始时间不能大于结束时间");
    return false;
  }
  loading.value = true;
  workOrderFee(queryParams.value).then((response) => {
    postList.value = response.page.list;
    total.value = response.page.totalCount;
    loading.value = false;
  })
}
function handleExport() {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以要加1，并且保证两位数格式
  const day = String(now.getDate()).padStart(2, '0'); // 日期保证两位数格式

  const currentDate = `${year}-${month}-${day}`;
  proxy.download(
    "pk-retirement/work-order-fee/export",
    {
      ...queryParams.value,
    },
    `上门服务费用${currentDate}.xlsx`,
  )
}
function handleQuery() {
  getList();
}
function resetQuery() {
  queryParams.value = {
    page: 1,
    limit: 10,
    applyName: undefined,
    planBeginTime: undefined,
    planEndTime: undefined,
  };
  getList();
}

function handinfo(data) {
  router.push({
    path: `/ticketManagement/returnVisitManagement/returnTicketDetails/${data.id}/1`,
  });
}
getList();
</script>
